﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.查询
{
    public partial class Frm客户历史信息查询 : DevExpress.XtraEditors.XtraForm
    {
        private String SYS_STYLE_ID;
        public Frm客户历史信息查询()
        {
            InitializeComponent();
        }

        private void textBox手机号_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                this.load信息(this.textBox手机号.Text.Trim());
            }
        }

        private void load信息(String mobile)
        {
            #region 客户基本信息
            String sql客户基本信息 = "SELECT\n" +
                "	CONCAT( a_customer_p.CUSTOMER_FIRST_NAME, a_customer_p.CUSTOMER_LAST_NAME ) AS `姓名`,\n" +
                "	a_customer_address_p.MOBILE AS `手机`,\n" +
                "	a_customer_address_p.CONSIGNEE AS `收货姓名`,\n" +
                "	CONCAT( a_customer_address_p.ADDRESS_PROVINCE_CD, a_customer_address_p.ADDRESS_CITY_CD, a_customer_address_p.ADDRESS_DISTRICT, a_customer_address_p.ADDRESS_DETAIL ) AS `地址` \n" +
                "FROM\n" +
                "	a_customer_address_p\n" +
                "	LEFT JOIN a_customer_p ON a_customer_address_p.CUSTOMER_ID = a_customer_p.CUSTOMER_ID \n" +
                "WHERE\n" +
                "	a_customer_address_p.MOBILE = '" + mobile + "';";
            #endregion
            this.gridControl客户基本信息.DataSource = SQLmtm.GetDataTable(sql客户基本信息);
            #region 历史订单
            String sql历史订单 = "SELECT\n" +
                "	s_style_p.SYS_STYLE_ID,\n" +
                "	o_order_p.ORDER_NO AS `订单号`,\n" +
                "	o_order_p.CUSTOM_NAME AS `订单姓名`,\n" +
                "	s_style_p.STYLE_NAME_CN AS `款式名称`,\n" +
                "	o_order_p.REMARKS AS `备注`,\n" +
                "	o_order_p.CREATE_DATE AS `下单时间` \n" +
                "FROM\n" +
                "	o_order_p\n" +
                "	LEFT JOIN s_style_p ON o_order_p.STYLE_ID = s_style_p.SYS_STYLE_ID \n" +
                "WHERE\n" +
                "	o_order_p.CUSTOMER_ID IN ( SELECT CUSTOMER_ID FROM a_customer_address_p WHERE a_customer_address_p.MOBILE = '"+mobile+"' )";
            #endregion
            this.gridControl历史订单.DataSource = SQLmtm.GetDataTable(sql历史订单);
        }

        private void gridView历史订单_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            this.SYS_STYLE_ID = FunctionHelper.GetgridViewValue(this.gridView历史订单, e.RowHandle, "SYS_STYLE_ID");
            #region 设计点
            String sql设计点 = "SELECT\n" +
                "	a_designoption_p.ITEM_NAME_CN AS `设计点类型`,\n" +
                "	adp.ITEM_NAME_CN AS `设计点名称`\n" +
                "FROM\n" +
                "	s_style_option_r\n" +
                "	LEFT JOIN a_designoption_p ON s_style_option_r.ITEM_VALUE = a_designoption_p.ITEM_VALUE\n" +
                "	LEFT JOIN a_designoption_p adp ON s_style_option_r.OPTION_VALUE = adp.ITEM_VALUE \n" +
                "WHERE\n" +
                "	SYS_STYLE_ID = '" + this.SYS_STYLE_ID + "';";
            #endregion
            this.gridControl设计点.DataSource = SQLmtm.GetDataTable(sql设计点);
        }
    }
}
